<script>
    var log = function() {
        var len = arguments.length;
        if (len === 1) {
            console.log(arguments[0])
        }else if (len === 2) {
            console.log(arguments[0],arguments[1]);
        }else{
            console.log(arguments[0],arguments[1],arguments[2])
        }
        console.log('')
    }

    //1. 任意字符 .
    var reg1 = /.../; 
    var str1 = 'asdsdasds'; //至少3个字符
    console.log('boo1',reg1.test(str1)); //true

    //2. \w 字母,数字,下划线
    var reg2 = /\w\w/;
    var str2 = 'as';
    console.log('boo2',reg2.test(str2)); //true
    console.log('boo2',reg2.test('$a')); //fales

    //3. \s 任意空白字符
    var reg3 = /..\s../;
    console.log('boo3',reg3.test('aa bb')); //true
    console.log('boo3',reg3.test('  aa  bb  ')); //true

    //4. \d 匹配数字,等同于[0-9]
    var reg4 = /\d\d\d\d/;
    console.log('boo4',reg4.test('9999')); //true

    //5. \D 匹配非数字,等同于\[^0-9]
    var reg5 = /\d\D\d/;
    console.log('boo5',reg5.test('233')); //false
    console.log('boo5',reg5.test('2a2dd')); //true

    //6. | 或匹配, 如 /x|y/ 正则可匹配 x 或 y 俩个字符
    var reg6 = /abc|xyz/;
    console.log('boo6',reg6.test('aavcbabcssddsadfdsgrd')); //true
    console.log('boo6',reg6.test('asdfcxyzfsadsadxyz'));    //true

    //7.[xyz] 表示包含 xyz 里面的任意一个,相当于x|y|z
    var reg7 = /[abc]/;
    log('boo7',reg7.test('aaa')); //true
    log('boo7',reg7.test('ddd')); //false
    
    //[a-zA-Z]  匹配所有得大小写字母
    var reg7 = /[a-zA-Z]/;
    var reg7 = /[0-9]/; //匹配0-9,相当于\d

    //8. [^x] 匹配除"x"之外的所有字符,其中"x"可以为任意字符
    var reg8 = /[^s]/;
    log('boo8',reg8.test('asdfd')); //true
    log('boo8',reg8.test('sss'))    //false

    //9. [^xyz] 同上,匹配除"x,y,z"之外的任意字符
    var reg9 = /[^abc]/;    //存在abc以外的字符都能匹配
    log('boo9',reg9.test('d')) //true
    log('boo9',reg9.test('ab')); //false

    //10. ^ 匹配字符串的开始
    var reg10 = /^[a-zA-Z]\w\w\w/;  //匹配:第一个字符是字母,紧跟三个字符(数字,字母或下划线)
    log('boo10',reg10.test('a_8a12k323')); //true
    log('boo10',reg10.test('8a_8a12k323')); //false
    var reg10 = /^1\d\d\d\d\d\d\d\d\d\d$/; //11位数字
    log('boo10',reg10.test('18711009559')); //true
    log('boo10',reg10.test('28711009559')); //false

    //11. \$ 匹配字符串的结果

    //12. \x 转义字符
    var reg12 = /\.com/;
    log('boo12',reg12.test('acom')); //false
    log('boo12',reg12.test('asdsadasdsa.com')); //true

    //'2021/05/05'
    var reg12 = /\d\d\d\d\/\d\d\/\d\d/;
    log('boo12',reg12.test(2021/05/05));

    //13. `?` 重复出现零次或一次
    var reg13 = /^https?/;
    log('boo13',reg13.test('http://sadasdsadsada')); //true
    log('boo13',reg13.test('https://dsadsadsadsa')); //true

    //14. `+` 重复出现一次或多次
    var reg14 = /a+/; //有一个a或者多个a都能匹配
    log('boo14',reg14.test('dsaaadfsadaa')) //true
    log('boo14',reg14.test('22222a')); //true

    //15. `*` 重复出现零次或多次
    var reg15 = /^https?.*/;
    log('boo15',reg15.test('http://dsadsadasdsa')); //true

    //16. {n} 重复出现 N次
    var reg16 = /^1\d{10}$/;

    //17. {n,} 至少重复出现 n 次
    var reg17 = /\d{10,}/; //至少有10个数字


    var reg = /b..k/;
    var str = 'books';
    var str2 = 'boooks';
    console.log(reg.test(str));  //true
    console.log(reg.test(str2));  //false

    var reg = /t\wq/;
    var str1 = '2222t2qkkk'
    var str2 = 'aaaaat$qbbbb';
    console.log(reg.test(str1)); //true
    console.log(reg.test(str2)); //false

    var reg = /\Dook/;
    var str = '8ook';
    console.log(reg.test(str)); //false

    var reg = /java\sscript/;
    var str = 'study java script'
    console.log(reg.test(str)); //true

    var reg = /javascript|html|css/;
    var str = 'study javascript';
    console.log(reg.test(str)); //true

    var reg = /^huruqing/;
    var str = 'huruqing123456'
    console.log(reg.test(str));  //true

    var reg = /^huruqing$/;
    var str = 'huruqing123456'
    console.log(reg.test(str)); //false

    var reg = /bo?k/;
    var str = 'book';
    console.log(reg.test(str)); //false

    var reg = /bo*k/;
    var str = 'boook';
    console.log(reg.test(str)); //true
    //+ 前面子表达式出现1次或多次
    var reg = /bo+k/;
    var str = 'boook';
    console.log(reg.test(str)); //true

    //{m,n}最少出现m次,最多出现n次
    var reg = /bo{2,4}k/;
    var str = 'boooook';
    console.log(reg.test(str)); //false

    //{m,}最少出现m次
    var reg = /bo{2,}k/;
    var str = 'booooook';
    console.log(reg.test(str)); //true

    //{m}正好出现m次
    var reg = /bo{2}k/;
    var str = 'boook';
    console.log(reg.test(str)); //false
    //反义
    var reg = /o[^usb]t/;
    var str = 'oat';
    console.log(reg.test(str)); //true

    var reg = /[a-zA-Z0-9]ook/;
    var str = '8ook';
    console.log(reg.test(str)); //true
</script>